package com.example.noelwhereismystuffs.support;

import java.util.List;

import com.example.noelproject.R;
import com.example.noelwhereismystuffs.models.Item;
import com.example.noelwhereismystuffs.models.LostItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyLostItemAdater extends ArrayAdapter<LostItem> {
	private static Context context;
	private static List<Item> lostItemList;

	/**
	 * 
	 * @param ctx
	 *            the context to use 
	 * @param lostItemList2
	 *            the array of lost items to display
	 */
	public MyLostItemAdater(Context ctx, List<Item> lostItemList2) {
		super(ctx, R.layout.row_layout);
		// TODO Auto-generated constructor stub
		context = ctx;
		lostItemList = lostItemList2;
	}

	/*
	 * overridden method that is called for each list item. The important
	 * parameter is position, which gives us the row number.
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// Set up the view by creating the widgets out of the xml spec
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.row_layout, parent, false);

		// Grab the widget in the view
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		
		// set the widget values
		textView.setText(lostItemList.get(position).getName());

		// lastly return the prepared view for the list to use
		return rowView;
	}
}
